<?php
class Muser extends CI_Model {
	public function __construct() {
		parent::__construct ();
		$this->load->database ();
	}
	public function saveUserDetails($userId, $details, $picture) {
		$data = array (
				"UserId" => $userId,
				"UserDetails" => $details, 
				"picture" => $picture
		);
		$this->db->insert ( "UserDetails", $data );
	}
	public function getUserDetails($userId) {
		$this->db->select ( "UserId", "UserDetails");
// 		$this->db->where ( "UserId", $userId );
		$query = $this->db->get ( "UserDetails" );
		return $query->result();
	}
	public function getUserPicture($userId) {
		$this->db->select ( "UserId", "picture");
		// 		$this->db->where ( "UserId", $userId );
		$query = $this->db->get ( "picture" );
		return $query->result();
	}
	public function checkExist($userId) {
		$this->db->where ( "UserId", $userId );
		$query = ( array ) $this->db->get ( "UserDetails" );
		echo "</br>";
		$num_rows = $query ["num_rows"];
		return ($num_rows != 0) ? true : false;
	}
	public function saveUserFriends($userId, $friendList) {
		$data = array (
				"UserId" => $userId,
				"Friends" => $friendList 
		);
		$this->db->insert ( "UserFriends", $data );
	}
	public function getUserFriends($userId) {
		$this->db->select ( "Friends" );
		$this->db->where ( "UserId", $userId );
		$query = $this->db->get ( "UserFriends" );
		return $query->result();
	}
	public function saveUserFriendLists($userId, $friendLists){
		$data = array(
			"UserId" => $userId,
			"FriendLists" => $friendLists
		);
		$this->db->insert("UserFriendList", $data);
	}
	public function getUserFriendLists($userId){
		$this->db->select("FriendLists");
		$this->db->where("UserId", $userId);
		$query = $this->db->get("UserFriendList");
		return $query->result();
	}
	public function savePostPrivacy($userId, $time, $functionName, $privacy, $tagNum){
		$data = array(
			"UserId" => $userId,
			"Time" => $time,
			"FunctionName" => $functionName,
			"Privacy" => $privacy,
			"TagNum" => $tagNum
		);
		$this->db->insert("UserUsages", $data);
	}
}